import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    component: () => import("@/views/login/noPass.vue"),
    hidden: true,
  },
  {
    path: "/login",
    component: () => import("@/views/login/inputPass"),
    hidden: true,
  },
  {
    path: "/home",
    name: "home",
    component: () => import("@/views/index/index"),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

// 全局前置守卫
router.beforeEach((to, from, next) => {
  try {
    // 设置标签栏名称
    document.title = "远程视频查勘系统"; // 默认标题
    if (to.meta && to.meta.title) {
      document.title = to.meta.title; // 根据路由元信息设置标题
    }
    next();
  } catch (error) {
    next(false); // 取消导航
  }
});

export default router;
